package com.neusoft.aclome.cmp.cloud.server.jcce.controller;

import com.alibaba.fastjson.JSONObject;
import com.neusoft.aclome.cmp.cloud.server.jcce.entity.TaskInfoToKt3;
import com.neusoft.aclome.cmp.cloud.server.jcce.service.DataResourceService;
import com.neusoft.aclome.cmp.cloud.server.jcce.service.JcceKT2Service;
import com.neusoft.aclome.cmp.cloud.server.pub.cloud.constants.PubApi;
import com.neusoft.aclome.cmp.cloud.server.service.ToolsService;
import com.neusoft.aclome.cmp.common.model.vo.HttpResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Api("JcceKT2Controller")
@RequestMapping("/jcce" + PubApi.VERSION + "/kt2")
@RestController
public class JcceKT2Controller {

    private static final Logger log = LoggerFactory.getLogger(JcceKT2Controller.class);

    @Autowired
    private JcceKT2Service kt2Service;

    @Autowired
    private DataResourceService dataResourceService;

    @Autowired
    private ToolsService toolsService;

    // 画工作流
    @PostMapping("/reportingProcess")
    @ApiOperation("上报流程信息")
    public HttpResponse reportingProcess(@RequestBody JSONObject jsonObject) {
        kt2Service.reportingProcess(jsonObject);
        return HttpResponse.resultSuccess();
    }


    @GetMapping("/getAllocation")
    @ApiOperation("获取流程信息")
    public HttpResponse getAllocation(@RequestParam(required = false) String returnId) {
        return HttpResponse.resultSuccess(kt2Service.processInfo(returnId));
    }

    // 获取任务分配
    @GetMapping("/getConfiguration")
    @ApiOperation("获取流程配置信息")
    public HttpResponse getConfiguration(@RequestParam (required = false) Integer processId,
                                         @RequestParam (required = false) String target) {
        return HttpResponse.resultSuccess(kt2Service.getConfiguration(processId,target));
    }

    // 杨斌
    @GetMapping("/getPrediction")
    @ApiOperation("资源预测,对接课题2")
    public HttpResponse getPrediction() {
        return HttpResponse.resultSuccess(kt2Service.getPrediction());
    }

    // 雍欣？
    @GetMapping("getConsultData")
    @ApiOperation("资源磋商,对接课题2")
    public HttpResponse getConsultData(@RequestParam(required = false) String mode,
                                       @RequestParam(required = false) String cpu,
                                       @RequestParam(required = false) String memory,
                                       @RequestParam(required = false) String gpu) {
        return HttpResponse.resultSuccess(kt2Service.getConsultData(mode, cpu, memory, gpu));
    }

    //  课题2概览页面
    @GetMapping("kt2Overview")
    @ApiOperation("课题2概览页面")
    public HttpResponse getConsultData() {
        return HttpResponse.resultSuccess(kt2Service.kt2Overview());
    }

    public static void main2(String[] args) {
        TaskInfoToKt3 info = new TaskInfoToKt3();
        info.setArrivalTime("2024-04-01 12:12:12");
        info.setStartTime("2024-04-01 15:43:15");
        info.setCpuDemand("8");
        info.setMemoryDemand("16");
        info.setStorageDemand("200");

        List<TaskInfoToKt3.AllocationInfo> infos = new ArrayList();
        TaskInfoToKt3.AllocationInfo i1 = new TaskInfoToKt3.AllocationInfo();
        TaskInfoToKt3.AllocationInfo i2 = new TaskInfoToKt3.AllocationInfo();
        TaskInfoToKt3.AllocationInfo i3 = new TaskInfoToKt3.AllocationInfo();

        i1.setJobIndex(0);
        i1.setJobName("ImageCapture");
        i1.setCloudPlatformId(1);
        i1.setCloudPlatformName("阿里云");
        i1.setInstanceType("ecs.n1.tiny");
        i1.setVirtualMachineId(1);
        i1.setVirtualMachineName("云演示虚机01");

        i2.setJobName("Thresholding Component");
        i2.setCloudPlatformId(2);
        i2.setCloudPlatformName("腾讯云");
        i2.setInstanceType("ecs.n1.tiny");
        i2.setVirtualMachineId(2);
        i2.setVirtualMachineName("云演示虚机02");

        i3.setJobIndex(2);
        i3.setJobName("ImageRotating");
        i3.setCloudPlatformId(1);
        i3.setCloudPlatformName("阿里云");
        i3.setInstanceType("ecs.n1.tiny");
        i3.setVirtualMachineId(3);
        i3.setVirtualMachineName("云演示虚机03");

        infos.add(i1);
        infos.add(i2);
        infos.add(i3);

        info.setTaskAllocationList(infos);

        System.out.println(JSONObject.toJSONString(info));


    }

}
